package com.pti.usermanager.web.controller;

import java.util.List;

import com.pti.usermanager.web.dto.request.SaveMenuRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pti.usermanager.dao.po.CompPo;
import com.pti.usermanager.service.api.CompService;
import com.pti.usermanager.web.dto.request.SaveCompRequest;
import com.pti.usermanager.web.dto.request.UpdateCompRequest;
import com.pti.usermanager.web.dto.response.ResultResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: CompController
 * @Author: dongzhipeng
 * @Description: 单位控制层
 * @Date: 2019/1/18
 */
@RestController
@Api(value = "单位管理接口",tags="提供单位的管理接口")
public class CompController {

    private static final Logger logger = LogManager.getLogger(CompController.class);

    @Autowired
    private CompService compService;

    @GetMapping("/comp/getCompTree/{compId}")
    @ApiOperation(value = "获取单位树结构" , notes = "获取单位树结构",produces = "application/json")
    public ResultResponse getCompTree(){
        return compService.findTreeByComp();
    }

    @GetMapping("/comp/getCompTree")
    @ApiOperation(value = "all单位" , notes = "all单位",produces = "application/json")
    public ResultResponse findAllList(@RequestParam(value = "compNm",required = false) String compNm){
        return compService.findAll(compNm);
    }

    @PostMapping("/comp/saveComp")
    @ApiOperation(value = "添加单位列表" , notes = "添加单位列表",produces = "application/json")
    public ResultResponse saveComp(@RequestBody SaveCompRequest saveCompRequest){
        return compService.saveComp(saveCompRequest);
    }

    @PutMapping("/comp/updateComp")
    @ApiOperation(value = "修改单位列表" , notes = "修改单位列表",produces = "application/json")
    public ResultResponse updateComp(@RequestBody UpdateCompRequest updateCompRequest){
        return compService.updateComp(updateCompRequest);
    }

    @DeleteMapping("/comp/delComp/{compId}")
    @ApiOperation(value = "删除单位" , notes = "删除单位",produces = "application/json")
    public ResultResponse delComp(@PathVariable(value = "compId") Long compId){
        logger.debug("compId:{}",compId);
        return compService.delComp(compId);
    }

    @GetMapping("/comp/compDetail/{compId}")
    @ApiOperation(value = "单位详情",notes = "单位详情",produces = "application/json")
    public ResultResponse findAllByPostId(@PathVariable("compId") Long compId){
        return compService.findAllByComdId(compId);
    }

}
